package main

import (
	"fmt"
	"github.com/uber/h3-go/v4"
)

func main() {
	// 1. lat/lng → H3 索引
	// vrs sta 30.920764 120.504402 7.046
	lat, lng := 30.4814, 114.3155
	res := 7
	index, err := h3.LatLngToCell(h3.LatLng{Lat: lat, Lng: lng}, res)
	if err != nil {
		panic(err)
	}
	ll, _ := index.LatLng()
	fmt.Printf("index = %s %.8f %.8f\n", index.String(), ll.Lat, ll.Lng)

	// 2. 索引 → 边界
	boundary, err := h3.CellToBoundary(index)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%.6f %.6f\n", ll.Lat, ll.Lng)
	for _, p := range boundary {
		fmt.Printf("%.6f %.6f\n", p.Lat, p.Lng)
	}

	// 3. 一圈邻居
	neighbors, err := h3.GridDisk(index, 1)
	if err != nil {
		panic(err)
	}
	fmt.Printf("neighbors = %d\n", len(neighbors))
}

/*
yd vrsgrid
114.307513 30.530442
114.377465 30.535927
114.439850 30.522912
114.306747 30.584028
114.298458 30.619124
114.260851 30.526762
114.198341 30.539704
114.308278 30.476819
114.309043 30.423161
114.368440 30.624576
114.438375 30.629986
114.439113 30.576467
114.376714 30.589490
114.251776 30.615466
114.189238 30.628419
114.190029 30.574831
114.260075 30.580363
114.199130 30.486059
114.199919 30.432377
114.262402 30.419450
114.261627 30.473124
114.378965 30.428691
114.448839 30.434180
114.378215 30.482327
114.448104 30.487793
*/
